package Eyjafjalla.monster;

import Eyjafjalla.power.GiveRedCloudPower;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.*;
import com.megacrit.cardcrawl.actions.utility.WaitAction;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.MonsterStrings;

public class TQB extends AbstractEyjafjallaMonster{
    public static final String ID = "eyjafjalla:TQB";
    private static final String MID_PATH = "TQB/enemy_1344_ddlamb";
    private static final MonsterStrings monsterStrings;
    private static final EnemyType TYPE = EnemyType.NORMAL;
    private static final String ATTACK_NAME = "Attack";
    private static final String IDLE_NAME = "Idle";
    private static final String DIE_NAME = "Die";

    static {
        monsterStrings = CardCrawlGame.languagePack.getMonsterStrings(ID);
    }

    boolean special = false;
    int attack;
    int defend;
    int red = 1;
    float waitTime = 0.3F;

    public TQB(float x,float y,boolean special){
        super(monsterStrings.NAME,ID,TYPE,96,240F,230F,x,y);
        setSpine(MID_PATH,1.6F);
        setFastMode();
        this.state.setAnimation(0,IDLE_NAME,true);

        this.special = special;
        if(AbstractDungeon.ascensionLevel>=7){
            setHp(special?40:80);
        }
        else {
            setHp(special?44:88);
        }
        if(AbstractDungeon.ascensionLevel>=2){
            attack = 16;
        }
        else {
            attack = 14;
        }
        if(AbstractDungeon.ascensionLevel>=17){
            defend = 20;
        }
        else {
            defend = 16;
        }

        this.damage.add(new DamageInfo(this,this.attack, DamageInfo.DamageType.NORMAL));

    }

    public void setFastMode(){
        if(Settings.FAST_MODE){
            state.setTimeScale(2);
            this.waitTime = 0.15F;
        }
        else{
            state.setTimeScale(1);
            this.waitTime = 0.3F;
        }
    }

    @Override
    public void usePreBattleAction() {
        addToBot(new ApplyPowerAction(this,this,new GiveRedCloudPower(this,(AbstractDungeon.ascensionLevel>=17&&!special)?2:1),(AbstractDungeon.ascensionLevel>=17&&!special)?2:1));
        super.usePreBattleAction();
    }

    @Override
    protected void getMove(int i) {
        if((i<70&&!lastTwoMoves((byte) 1))||lastMove((byte) 2)){
            this.setMove((byte) 1,Intent.ATTACK,this.damage.get(0).base);
        }
        else {
            this.setMove((byte) 2,Intent.DEFEND_BUFF);
        }
    }

    @Override
    public void takeTurn() {
        setFastMode();
        switch (this.nextMove){
            case 1:{
                addToBot(new ChangeStateAction(this,"ATTACK"));
                addToBot(new WaitAction(this.waitTime));
                addToBot(new DamageAction(AbstractDungeon.player,this.damage.get(0), AbstractGameAction.AttackEffect.SLASH_DIAGONAL));
                break;
            }
            case 2:{
                addToBot(new GainBlockAction(this,defend));
                addToBot(new ApplyPowerAction(this,this,new GiveRedCloudPower(this,red),red));
                break;
            }
        }

        addToBot(new RollMoveAction(this));
    }

    @Override
    public void changeState(String stateName) {
        switch (stateName){
            case "ATTACK":{
                this.state.setAnimation(0,ATTACK_NAME,false);
                this.state.addAnimation(0,IDLE_NAME,true,0F);
                break;
            }
            default:
                break;
        }
    }

    @Override
    public void die() {
        this.state.setTimeScale(1F);
        state.setAnimation(0,DIE_NAME,false);
        super.die();

    }
}
